#import "ColinFlutterPlugin.h"

@implementation ColinFlutterPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  FlutterMethodChannel* channel = [FlutterMethodChannel
      methodChannelWithName:@"colin_flutter"
            binaryMessenger:[registrar messenger]];
  ColinFlutterPlugin* instance = [[ColinFlutterPlugin alloc] init];
  [registrar addMethodCallDelegate:instance channel:channel];
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
  if ([@"getPlatformVersion" isEqualToString:call.method]) {
    result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
  }  else if ([@"openWifiSettings" isEqualToString:call.method]) {
       [self openAppSettings:result];
  } else {
    result(FlutterMethodNotImplemented);
  }
}

- (void)openAppSettings:(FlutterResult)result {
    if (@available(iOS 10, *)) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]
                                           options:[[NSDictionary alloc] init]
                                 completionHandler:^(BOOL success) {
                                     //result([[NSNumber alloc] initWithBool:success]);
                                     result(@"iOS 10 isOK");
                                 }];
    } else if (@available(iOS 8.0, *)) {
        BOOL success = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
        //result([[NSNumber alloc] initWithBool:success]);
        result(@"iOS 8.0 isOK");
    } else {
        //result(@false);
        result(@"iOS false");
    }
}

@end
